namespace BM.Tools.WebControls.MForm.Generator
{
    using System;    
    using System.ComponentModel;    

    using Templates;    

    /// <summary>
    /// This class can be used to provide additional settings to the <see cref="FormBuilder"/>.
    /// </summary>
    public class FormBuilderSettings
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FormBuilderSettings"/> class.
        /// </summary>
        public FormBuilderSettings()
        {                        
            ForceTextareaLength = 100;
            GenerateOrdinal = true;
            AlwaysPlaceLeafsFirst = true;
            LeafMaxOccursBound = 50;
            NonLeafMaxOccursBound = 20;
        }

        /// <summary>
        /// Gets or sets the event handler when the leaf is created.
        /// </summary>
        public EventHandler<ItemTemplateCreationEventArgs> LeafCreated
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the event handler when any list item is created.
        /// </summary>
        public EventHandler<ListItemCreationEventArgs> ListItemCreated
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the event handler when a branch/choice/rootis created.
        /// </summary>
        public EventHandler<ItemTemplateCreationEventArgs> OffspringsOwnerCreated
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the identity constraint creation value handler
        /// </summary>        
        [Browsable(false)]
        public EventHandler<IdentityConstraintCreationEventArgs> IdentityConstraintCreated
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the builder should ignore MinOccurs in non-leaf items.
        /// </summary>
        [DescriptionAttribute(@"Should the minOccurs attribute for non-leaf items be ignored? (It might be useful for displaying a form in view mode, where a provided XML contains only partial data)")]
        [DefaultValue(false)]
        public bool IgnoreNonLeafMinOccurs
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the builder should ignore MinOccurs in leaf items.
        /// </summary>      
        [DescriptionAttribute(@"Should the minOccurs attribute for leaf items be ignored? (It might be useful for displaying a form in view mode, where a provided XML contains only partial data)")]
        [DefaultValue(false)]
        public bool IgnoreLeafMinOccurs
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether the builder should sort the items and place leafs before the rest.
        /// </summary>      
        [DescriptionAttribute(@"Should always place leafs before branches and choices? (By default true)")]
        [DefaultValue(true)]
        public bool AlwaysPlaceLeafsFirst
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the value of the max occurs bound for leafs
        /// </summary>
        [DescriptionAttribute(@"It is possible in xml schema that there can be theoretically unbounded number of elements.
However a web form should always have limitations for adding elements. What should be the maxOccurs bound for leaf elements?")]
        [DefaultValue(50)]
        public int LeafMaxOccursBound
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the value of the max occurs bound for non-leafs
        /// </summary>
        [DescriptionAttribute(@"It is possible in xml schema that there can be theoretically unbounded number of elements.
However a web form should always have limitations for adding elements. What should be the maxOccurs bound for non-leaf elements?")]
        [DefaultValue(20)]
        public int NonLeafMaxOccursBound
        {
            get;
            set;
        }                

        /// <summary>
        /// Gets or sets the force textarea length.
        /// </summary>        
        [DescriptionAttribute("From what items maximal length should multirow TextBox be generated?")]
        [DefaultValue(100)]
        public int ForceTextareaLength
        {
            get;
            set;            
        }

        /// <summary>
        /// Gets or sets a value indicating whether GenerateResourceKeys.
        /// </summary>  
        [DescriptionAttribute("Should be meta:resourceKey attributes generated?")]
        [DefaultValue(false)]
        public bool GenerateResourceKeys
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets a value indicating whether Ordinal property should be generated.
        /// </summary>
        [DescriptionAttribute(@"MForm controls use the ""Ordinal"" property to determine the order of xml elements.
The order of xml elements is necessary to conform to xml schema sequence constraint.
If the ""Ordinal"" property is generated, controls display order can be changed 
without concerns about the output xml validity. 
However if the xml is used only to be object serialized/deserialized, 
the order of xml elements is not taken into account.")]
        [DefaultValue(true)]
        public bool GenerateOrdinal
        {
            get;
            set;
        }
    }
}